home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / dev / gui / gengui2.lha / GenGui2 / Gengui.doc next >
Text File  |  1995-04-19  |  40KB  |  1,236 lines

  1.  
  2.  
  3.                            GenGui V2.0
  4.                            ===========
  5.  
  6.                     ©1994-95 by Matthias Meixner
  7.  
  8.                Read the README file for the legal issues
  9.  
  10.  
  11. This package is for layout and creation of graphical user interfaces (GUI).
  12. Unlike some other programs like Gadtools, you do not draw your GUI just like
  13. in a paint-program, but you describe the GUI in a kind of description
  14. language. From this description GenGui generates a C-headerfile, wich
  15. containes the description data in a form that is needed by the routines
  16. which must be linked to your program and which do the real work on runtime.
  17.  
  18. For the legal issues read the "readme"-file.
  19.  
  20.  
  21.  
  22. 1. Preface
  23. ==========
  24.  
  25. From version 36 of the Amiga operating system it on is possible to select
  26. the font that should be used. Since there are now several new display-
  27. resolutions it is highly recommended, that applications should be able to
  28. use higher resolutions and therefore it is required, that programs can adapt
  29. to a variable windowsize.
  30. OK, lets face the current situation. There are half a dozen different
  31. systems out there, that all allow to create font-sensitive and resizeable
  32. GUIs. Most of them come with a shared library, that implemets its own
  33. gadgets, and they are all about 100kBytes in size. Since there is no
  34. standard for these tools yet, every programmer uses his preferred generator
  35. and every program uses another shared library. But what's the use of shared-
  36. libraries, if every program uses another one? If you have got three programs
  37. running, that all use a different library, then the libraries allocate
  38. already 300kBytes just for three layout-engines and for many unused button-
  39. types, each implementing their own version of the same types of buttons.
  40. Therefore I wrote Gengui. It uses GadTools-gadgets, which already come with
  41. the operating system and implements a layout-enging for these gadgets. It
  42. does not use a shared-library, but comes as a quite small link-library.
  43.  
  44.  
  45.  
  46. 2. The basic idea:
  47. ==================
  48.  
  49. The description of the Gui is box oriented. Every box affects the size
  50. and position of the objects inside the box. A box has an orientation, which
  51. determines the positions of the objects in a box, in a vertical box the
  52. first object is on top and all other objects are below this one, in a
  53. horizontal box, the first one is on the most left side. Within a box every
  54. object can have a relative size, a size absolut in characters or a size
  55. absolut in pixels or a mixture of the last two. This object can be a new box,
  56. a gadget or a custom "gadget". This allows an easy generation of resizeable
  57. GUI's.
  58.  
  59. Maybe you should get an example now:
  60.  
  61. Imagine you want to have a GUI, which looks like that:
  62.  
  63.  
  64. +-------------------------+
  65. |                         |
  66. | +-----+ +-----+ +-----+ |
  67. | |Text1| |Text2| |Text3| |
  68. | +-----+ +-----+ +-----+ |
  69. |                         |
  70. |                         |
  71. |                         |
  72. +-------------------------+
  73.  
  74. The description would look like this:
  75.  
  76. PROJECTNAME Project1 // This is the name, which will be used
  77.                      // in the generated source
  78.  
  79. HBOX                 // horizontal box
  80.    VREL 1            // the box has relative height
  81.    HREL 1            // and relative width
  82.    BUTTON            // We want to generate a button
  83.       STDLINE 1      // with a height of one line plus spacing
  84.       HREL 1         // and relative width
  85.       TEXT "Text1"   // "Text1" should be written in it
  86.       ID   1         // and maybe we want to identify it later
  87.    END
  88.    BUTTON
  89.       STDLINE 1
  90.       HREL 1
  91.       TEXT "Text2"
  92.       ID   2
  93.    END
  94.    BUTTON
  95.       STDLINE 1
  96.       HREL 1
  97.       TEXT "Text3"
  98.       ID   3
  99.    END
  100. END
  101.  
  102. This would describe a GUI with three gadgets, each has (including an adequate
  103. spacing) one third of the width of the window, and a height of one line.
  104.  
  105. Gengui offers some reasonable defaultvalues for the different types of
  106. objects, which significantly reduce the size of the description:
  107.  
  108.  
  109. PROJECTNAME Project1
  110. HBOX
  111.    BUTTON
  112.       TEXT "Text1"
  113.       ID   1
  114.    END
  115.    BUTTON
  116.       TEXT "Text2"
  117.       ID   2
  118.    END
  119.    BUTTON
  120.       TEXT "Text3"
  121.       ID   3
  122.    END
  123. END
  124.  
  125.  
  126. Maybe you want the first button to be double as wide as the other two
  127. buttons:
  128.  
  129.  
  130. PROJECTNAME Project1
  131. HBOX
  132.    BUTTON
  133.       HREL 2        // now this button gets 2 parts of the width of this box
  134.       TEXT "Text1"
  135.       ID   1
  136.    END
  137.    BUTTON           // whereas this button gets only one part,
  138.       TEXT "Text2"
  139.       ID   2
  140.    END
  141.    BUTTON           // and this one too
  142.       TEXT "Text3"
  143.       ID   3
  144.    END
  145. END
  146.  
  147.  
  148.  
  149. Now lets think of something like that:
  150.  
  151. +-----------------+
  152. |                 |
  153. | +-------------+ |
  154. | |             | |
  155. | +-------------+ |
  156. |                 |
  157. | +--------+      |
  158. | |        |      |
  159. | +--------+      |
  160. |                 |
  161. | +---+           |
  162. | |   |           |
  163. | +---+           |
  164. |                 |
  165. +-----------------+
  166.  
  167. The first button has three times the size and the second one two times the
  168. size of the last button.
  169.  
  170.  
  171. PROJECTNAME Project1
  172. VBOX                    // Now one button is above the other !
  173.    BUTTON
  174.       HREL 3            // Three thimes the size
  175.       TEXT "Text1"
  176.       ID   1
  177.    END
  178.    BUTTON
  179.       HREL 2            // two times the size of the last button.
  180.       TEXT "Text2"
  181.       ID   2
  182.    END
  183.    BUTTON
  184.       TEXT "Text3"
  185.       ID   3
  186.    END
  187. END
  188.  
  189.  
  190.  
  191. And now a last example for this topic:
  192.  
  193. +---------------+
  194. |               |
  195. |      +------+ |
  196. |      |      | |
  197. |      +------+ |
  198. |               |
  199. | +--+ +------+ |
  200. | |  | |      | |
  201. | |  | |      | |
  202. | |  | |      | |
  203. | |  | |      | |
  204. | +--+ +------+ |
  205. |               |
  206. +---------------+
  207.  
  208. PROJECTNAME Pro2
  209. HBOX
  210.  
  211.    VBOX        // left box
  212.       HREL 1
  213.  
  214.       VBOX     // this creates the empty place in the top left corner
  215.       END
  216.  
  217.       BUTTON
  218.          VREL2
  219.       END
  220.    END
  221.  
  222.    VBOX        // right box
  223.       HREL 2   // of double width
  224.  
  225.       BUTTON
  226.          VREL 1
  227.       END
  228.  
  229.       BUTTON
  230.          VREL 2
  231.       END
  232.    END
  233.  
  234. END
  235.  
  236.  
  237.  
  238. 3. Installation
  239. ===============
  240.  
  241. Installation is quite easy:
  242.  
  243. copy gengui.h to your include: directory or you will have to add the path
  244. where it can be found to your include-path.
  245.  
  246.  
  247.  
  248. 4. The description language
  249. ===========================
  250.  
  251. These are the keywords of the description languange. It does not distinguish
  252. between lower- and uppercase. Some keywords have more than one name, since
  253. i could not decide wich one would be more easy to remember :). These other
  254. names can be found in the brackets ().
  255.  
  256. Every command must be on a separate line, comments begin with '//' and mark
  257. the rest of the line as comment.
  258.  
  259. #c_source
  260. #end_source
  261.  
  262.    Everything between these two lines will be directly included in the
  263.    generated output. These keywords must begin on the first column !
  264.  
  265.  
  266. These are the commands that are used to describe the objects of the GUI:
  267.  
  268. BACKFILL Hook: Install a Backfill Hook, that is used for rendering
  269.                the background of this box.
  270.  
  271. BAR
  272.    BAR      : Insert a bar between two objects. The direction depends on
  273.               the containing object. If this is a VBOX, then a horizontal
  274.               bar will be generated, otherwise a vertical bar.
  275.  
  276. BUTTON
  277.    BUTTON   : Normal button, default size HREL 1, STDLINE 1,
  278.               MINHCHAR strlen(Text), MINHPIX 4
  279.  
  280.  
  281. CHECKBOX
  282.    CHECKBOX : Checkbox, default size HCAR 2, VCHAR 1
  283.  
  284.  
  285. CUSTOM
  286.    CUSTOM   : Custom Gadget, default size HREL 1, VREL 1,
  287.               Read also the chapter about custom gadgets !
  288.  
  289. CYCLE
  290.    CYCLE    : Cycle-gadget, default size HREL 1, STDLINE 1
  291.               MINHCHAR max(strlen(Texts in the Cyclegadget)),
  292.               MINHPIX 24
  293.  
  294.  
  295. FRAME
  296.    FRAME RAISED|RECESSED
  297.             : Draw a frame around this Box (VBOX or HBOX).
  298.               It is raised (FRAME RAISED) or recessed (FRAME RECESSED).
  299.  
  300. GFXBUTTON   : Graphical button. It supports two highlight-methods:
  301.               complement and highlight-image. The images are selected within
  302.               this block with the "IMAGE" command. If there is one such
  303.               command, then complement is used, if there are two of them,
  304.               then the second one is used for highlighting.
  305.  
  306.               You can adjust the alignment within its space with the
  307.               following flags:
  308.  
  309.                   Horizontal alignment: GG_Left,GG_HCentered,GG_Right
  310.                   Vertical alignment:  GG_Top,GG_VCentered,GG_Bottom
  311.  
  312.                   default: GG_Left,GG_Top
  313.  
  314.               You can switch off highlighting by the GG_NoHighlight-flag.
  315.  
  316.  
  317. HBOX
  318.    HBOX     : horizontal box, default size: HREL 1, VREL 1
  319.  
  320. INTEGER
  321.    INTEGER  : Integer-gadget, default size HREL 1, STDLINE 1
  322.  
  323. LISTVIEW
  324.    LISTVIEW : default size HREL 1, VREL 1
  325.  
  326. MX
  327.    MX       : MX-gadget, default size HREL 1, VREL 1,
  328.               MINVCHAR # of entries, MINVPIX 6
  329.  
  330. NUMBER
  331.    NUMBER   : Number-gadget, default size HREL 1, STDLINE 1
  332.  
  333. PALETTE
  334.    PALETTE  : Palette-gadget, default size HREL 1, VREL 1
  335.  
  336. PLAINTEXT
  337.    PLAINTEXT: Formatted Text, default size HREL 1, STDLINE 1.
  338.               MINHPIX and MINVPIX are set according to the size of the
  339.               text as default.
  340.               Plaintext supports the following format descriptions:
  341.  
  342.                   \n  : Newline
  343.                   %%  : '%'
  344.  
  345.                   %Cx : Set foreground color to x
  346.                         (e.g. %C1 : set color to 1)
  347.                   %cx : Set background color to x
  348.  
  349.                   %B  : Bold on
  350.                   %b  : Bold off
  351.                   %I  : Italics on
  352.                   %i  : Italics off
  353.                   %N  : Normal style (Bold,Italics,Underlined off)
  354.                   %U  : Underlined on
  355.                   %u  : Underlined off
  356.  
  357.               You can adjust the alignment within its space with the
  358.               following flags:
  359.  
  360.                   Horizontal alignment: GG_Left,GG_HCentered,GG_Right
  361.                   Vertical alignment:  GG_Top,GG_VCentered,GG_Bottom
  362.  
  363.                   default: GG_Left,GG_Top
  364.  
  365.               Unlike TEXT this is not a gadtools gadget, but allows easier
  366.               formatting of text, since it allows texts, that use more
  367.               than one color, style or that span more than one line.
  368.  
  369.               See also GfxPrint();
  370.  
  371. SCROLLER
  372.    SCROLLER : Scroller, default size HREL 1, VREL 1
  373.  
  374. SLIDER
  375.    SLIDER   : Slider, default size HREL 1, VREL 1
  376.  
  377. STRING
  378.    STRING   : String-gadget, default size HREL 1, STDLINE 1
  379.  
  380. TEXT
  381.    TEXT     : Text-gadget, default size HREL 1, STDLINE 1
  382.               See also PLAINTEXT
  383.  
  384. VBOX
  385.    VBOX     : vertical box, default size: HREL 1, VREL 1
  386.  
  387.  
  388. Each of these commads defines a block, which must be terminated by "END"
  389.  
  390.  
  391.  
  392. Commands specifying the size of the objects:
  393.  
  394. HCHAR (XCHAR)
  395.    HCHAR chars   : Absolute width of 'chars' characters
  396.  
  397. HPIX (XPIX)
  398.    HPIX pixel    : Absolute width of 'pixel' pixels
  399.  
  400. HREL (XREL)
  401.    HREL size     :  Relative width
  402.  
  403. STDCOL
  404.    STDCOL chars  : Absolute width of 'chars' characters plus 4 pixels space
  405.  
  406. STDLINE
  407.    STDLINE chars : Absolute height of 'chars' characters plus 4 pixels space
  408.  
  409. VCHAR (YCHAR)
  410.    VCHAR chars   : Absolute height of 'chars' characters
  411.  
  412. VPIX (YPIX)
  413.    VPIX pixel    : Absolute height of 'pixel' pixels
  414.  
  415. VREL (YREL)
  416.    VREL size     : Relative height
  417.  
  418. XSPACE
  419.    XSPACE xs     : Set the amount of horizontal space between gadgets to
  420.                    xs pixels, defaults to INTERWIDTH
  421.                    (only allowed within HBOX/VBOX)
  422. YSPACE
  423.    YSPACE ys     : Set the amount of vertical space between gadgets to
  424.                    ys pixels, defaults to INTERHEIGHT
  425.                    (only allowed within HBOX/VBOX)
  426.  
  427.  
  428. Commands specifying the minimal size for relative objects:
  429.  
  430. MINHCHAR (MINXCHAR)
  431.    MINHCHAR chars   : Minimal width of 'chars' characters
  432.  
  433. MINHPIX (MINXPIX)
  434.    MINHPIX pixel    : Minimal width of 'pixel' pixels
  435.  
  436. MINSTDCOL
  437.    MINSTDCOL chars  : Minimal width of 'chars' characters plus 4 pixels space
  438.  
  439. MINSTDLINE
  440.    MINSTDLINE chars : Minimal height of 'chars' characters plus 4 pixels space
  441.  
  442. MINVCHAR (MINYCHAR)
  443.    MINVCHAR chars   : Minimal height of 'chars' characters
  444.  
  445. MINVPIX (MINYPIX)
  446.    MINVPIX pixel    : Minimal height of 'pixel' pixels
  447.  
  448. These commands specify the minimal width/height for objects with relative
  449. width/height. It does not affect the relative sizes of different objects.
  450. Thus if you have two objects within one box, each having the same relative
  451. width and one of these has a minimal width of 5 chars and the other one
  452. of 6 chars, then the minimal width of the first one will also be 6 chars,
  453. since the relative size says, that the two objects have always the same
  454. width.
  455. The default values used by Gengui for the minimal sizes are often sufficient
  456. enougth, therefore you will not need to use these commands too often.
  457. (At least I hope so :-) )
  458.  
  459.  
  460. Commands for the description of gadget-specific data:
  461.  
  462. CUSTOM
  463.    CUSTOM func   : Set the custom function for custom-gadgets.
  464.                    NOTE: this is only valid within a custom-object and since
  465.                          it is written the same way as the CUSTOM-object
  466.                          the meaning of CUSTOM only depends on the context.
  467.  
  468. FLAGS
  469.    FLAGS flagset : Set the flags of the gadget (-> ng_Flags)
  470.                    NOTE: it is possible spread the flags to more than one
  471.                          FLAGS command e.g.:
  472.  
  473.                             FLAGS a|b
  474.  
  475.                          would have the same effect as
  476.  
  477.                             FLAGS a
  478.                             FLAGS b
  479.  
  480.  
  481. HOOK
  482.    HOOK function : Set a hook function that is called, when the gadget sends
  483.                    a message. See also the chapter on hook-functions.
  484.  
  485. ID
  486.    ID id         : Set the ID of the gadget (-> ng_GadgetID)
  487.                    NOTE: id must not contain any whitespace characters !
  488.                    The value of the ID must be >=0.
  489.  
  490. IMAGE
  491.    IMAGE image   : This sets the image-data for GFXBUTTONs. "image" must
  492.                    point to a "struct Image" variable. You can generate this
  493.                    data using IconEdit when you have set "SRC" in the
  494.                    tooltypes of IconEdit. Then you will find "Save as C..."
  495.                    in the projects menu. Since IconEdit generates some
  496.                    additional information for the icons, you will need to
  497.                    delete this information from the generated sourcecode.
  498.                    You may define up to two images for every GFXBUTTON.
  499.                    If there are two of them, then the second one is used for
  500.                    highlighting.
  501.  
  502. TAGS
  503.    TAGS tags     : Set the tags for a gadget. You need not set TAG_DONE,
  504.                    since this is automatically done. You may use more than
  505.                    one TAGS command per gadget, e.g.
  506.  
  507.                      TAGS a,b
  508.                      TAGS c,d
  509.  
  510.                    would have the same effect as
  511.  
  512.                      TAGS a,b,c,d
  513.  
  514. TEXT
  515.    TEXT string   : Set the text for the gadget (-> ng_GadgetText)
  516.                    If you specify more than one text, then all these texts
  517.                    are concatenated.
  518.  
  519. TEXTATTR
  520.    TEXTATTR textattr : Set ng_TextAttr. By default the standart font of the
  521.                        window is used for the gadgets.
  522.  
  523. USER
  524.    USER userdata : Set user data. You can access the user data via the
  525.                    macro GetUserData().
  526.                    NOTE: the field ng_UserData is required by GenGui itself,
  527.                          but therefore it has another field reserved for
  528.                          this purpose.
  529.  
  530.  
  531. General note: The parameters of all these commands may be preprocessor
  532.               symbols, in fact they are just passed on to the generated
  533.               source.
  534.  
  535.  
  536.  
  537. 5. What's generated by GenGui
  538. =============================
  539. GenGui takes the descriptionfile and generates two headerfile. The first
  540. headerfile contains the full data of the descriptionfile and some required
  541. or useful defines. First it contains a struct WinInfo that has the name which
  542. was set using the command projectname. This struct is required for rendering
  543. the GUI to the window, therefore it is the most important structure in the
  544. headerfile. It allocates GadInfo structures, which store the information of
  545. the look of the GUI. To make these accessible for GG_SetLowlevelAttrs()
  546. Gengui generates defines which are used to supersede the generic names of
  547. the structure valiables. The names have the form:
  548.  
  549. 'Projectname'_GadInfo_'GadgetID'
  550.  
  551. They identify the variables themselves. Therefore you will need to use the
  552. &-operator to get the address of them for use with GG_SetLowlevelAttrs().
  553.  
  554. Furthermore an array of pointers to gadgets is allocated in the headerfile.
  555. The name of this array has the form:
  556.  
  557. 'Projectname'_Gadgets
  558.  
  559. This array contains the pointers to the gadgets which you require for e.g.
  560. setting new attributes of the gadgets via GG_SetGadgetAttrs(). But note,
  561. that these entries are only valid as long as the GUI is rendered to the
  562. window and that these entries change when the GUI is resized or changed in
  563. other ways. To know which entry in this array belongs to a certain gadget,
  564. GenGui generates a definition for every Gadget, which tells you which entry
  565. belongs to a certain gadget. The name of this definition has the form:
  566.  
  567. 'Projectname'_'GadgetID'
  568.  
  569. OK, let's have a simple example to illustrate, how you would use it. The
  570. second headerfile has the extension "_def.h" and contains only the structure
  571. definitions, the prototypes, the "extern" references and the #defines. It is
  572. useful if you want to access the GUI from another module.
  573.  
  574. This could be a description of a GUI:
  575.  
  576. #c_source
  577.  
  578. #define ExampleButton 1  // I want to have a more telling name than a number
  579.  
  580. #end_source
  581.  
  582. Projectname Test
  583. VBOX
  584.    BUTTON
  585.       TEXT "Test"
  586.       ID ExampleButton
  587.    end
  588. end
  589.  
  590.  
  591. To render the GUI to the window you would use:
  592.  
  593.    RenderGui(window,&Test);
  594.  
  595. And to change the attributes of the gadget you would use:
  596.  
  597.    GG_SetGadgetAttrs(Test_Gadgets[Test_ExampleButton],window,NULL, ... );
  598.  
  599. Or for lowlevel changes:
  600.    GG_SetLowlevelAttrs(&Test_GadInfo_ExampleButton, .... );
  601.  
  602.  
  603. For the handling of gadgets, there are some useful macros in gengui.h,
  604. which is automatically included in the generated headerfiles:
  605.  
  606. GetGadget()    generates the address of the selected gadget from the
  607.                received IntuiMessage:
  608.  
  609.                struct Gadget *GetGadget(struct IntuiMessage *)
  610.  
  611.  
  612. GetInfo()      calculates the address of the GadInfo structure from the
  613.                address of the gadget.
  614.  
  615.                struct GadInfo *GetInfo(struct Gadget *)
  616.  
  617.  
  618. GetString()    takes the address of a string-gadget and retrieves a pointer
  619.                to the contents of the buffer.
  620.  
  621.                UBYTE *GetString(struct Gadget *)
  622.  
  623.  
  624. GetNumber()    retrieves the value stored in a number-gadget.
  625.  
  626.                LONG GetNumber(struct Gadget *)
  627.  
  628.  
  629. GetUserData(): Since Gengui needs the field "UserData" for internal use, it
  630.                reserves another field for this purpose, it generates a this
  631.                macro GetUserData() that fullfills the purpose of accessing
  632.                this field for userdata.
  633.  
  634.                ULONG GetUserData(struct Gadget *)
  635.  
  636.  
  637. For the handling of customgadgets you require some additional defines:
  638. First there are some "modes" defined, whose meaning is explained in the
  639. chapter for customgadgets.
  640.  
  641. The other structures in the headerfile contain the actual data that
  642. describes the GUI. Since they are not important for the programmer their
  643. names consist of the projectname and an extension of some numbers and
  644. characters.
  645.  
  646. If you want to know more of what can be found in the headerfile you should
  647. have a look at the generated source :).
  648.  
  649.  
  650.  
  651. 6. Writing code using GenGui
  652. ============================
  653. The first thing you have to do is to write the file with the description of
  654. the GUI in the description-language, that was presented in chapter 2. The
  655. filename must have the extension .gui. The next step is to compile this
  656. description to a normal C-headerfile using GenGui:
  657.    GenGui  file.gui
  658.  
  659. You will get two headerfiles: file.h and file_def.h
  660. "file.h" contains the data of the GUI and "file_def.h" contains all from
  661. "file.h" except for the data itself.
  662.  
  663. There are two important aspects:
  664.  - You must use Gui_GetIMsg() instead of GT_GetIMsg()!
  665.  - You must use Gui_SetGadgetAttrs() instead of GT_SetGadgetAttrs()!
  666.  
  667. The following example will show you how to use these GUI's within your own
  668. programs:
  669.  
  670. #include "file.h"  // include the headerfile that was generated by GenGui
  671.  
  672. main()
  673. {
  674.    struct IntuiMessage *msg;
  675.    struct WIndow *win;
  676.    int run=1;
  677.  
  678.    /*
  679.  
  680.    . Now open all required libraries and the window. "win" must point to
  681.    . the newly opened window.
  682.  
  683.    */
  684.  
  685.    /* The Projectname of the GUI is TestPro */
  686.  
  687.    if(RenderGui(win,&TestPro)) {/* do the cleanup, send an error msg .... */}
  688.             /* RenderGui returns 0 if successful, an error code on failure */
  689.  
  690.    while(run) {
  691.       WaitPort(win->UserPort);  // you may use Wait instead, if you like :)
  692.  
  693.       while(msg=GG_GetIMsg(win->UserPort)) {
  694.             /* It is very important that you use this function instead of
  695.                GetMsg or GT_GetIMsg(), since it does some additional
  696.                actions !!! */
  697.  
  698.          switch(msg->Class) {
  699.             case IDCMP_CLOSEWINDOW: run=0;break;
  700.             case IDCMP_NEWSIZE:     ResizeGui(&TestPro); // do the resizing
  701.                                     break;
  702.             case IDCMP_REFRESHWINDOW:
  703.                                     RefreshGui(&TestPro); // and the refresh
  704.                                     break;
  705.             // ... and some more actions you need
  706.          }
  707.          GG_ReplyIMsg(msg);
  708.       }
  709.    }
  710.  
  711.    FreeGui(&TestPro); // Free the gadgets
  712.  
  713.    /* close the window and free the sources etc. */
  714. }
  715.  
  716. When opening the window you should consider that it must be large enough to
  717. have room for all gadgets. If the window is too small then the GUI will look
  718. quite messed up. You can determine the minimal required size with the
  719. GG_MinSize function, at least when the MIN-sizes are correctly set. Or you
  720. can use GG_SmartRenderGui, which takes care of the needed size and moves or
  721. resizes the window due to these requirements. It even substitutes the font
  722. used in the window by a smaller one, if required.
  723.  
  724.  
  725.  
  726.  
  727. 5. Hook functions
  728. =================
  729. For every gadget you may define a hook-function. This function is called
  730. whenever Intuition sends a message for this gadget. It receives the address
  731. of the Intuimessage as parameter and must return an int as result. If you
  732. return null then the Intuimessage is passed on to your main program, in the
  733. other case the Intuimessage is ignored and your program will not receive
  734. this message any more:
  735.  
  736. int __stdargs HookFunction(struct IntuiMessage *msg)
  737. {
  738.    int ignore=1; /* The IntuiMessage will not be passed on to the program */
  739.  
  740.  
  741.    /* do some actions */
  742.  
  743.    return ignore;
  744. }
  745.  
  746.  
  747.  
  748. 7. Custom gadgets
  749. =================
  750. Custom gadgets are a very powerful element for generating graphical user
  751. interfaces. They not only allow you to add gadgets other than gadtools
  752. gadgets, you can also use it to render information to the window, that is
  753. not really a gadget, for example some borders or texts, which should
  754. be resizeable. And a special thing which you can create using customgadgets
  755. are multiplexed user interfaces. "What's that?", you may ask. OK, I'll give
  756. you an idea, what you can achieve by this. Imagine that there is not enough
  757. room in the window to place all gadgets in it. Then you could have e.g. a
  758. cyclegadget with which you can select the group of gadgets you want to
  759. be visible in the window.
  760. First at all every customgadget requires a function that handles the
  761. creation of the "gadget". This function gets 7 arguments, the first one is
  762. a pointer to a WinInfo structure, the second one is a pointer to a NewGadget
  763. structure which was filled with all needed data (only MODE_NEW,MODE_RESIZE
  764. and MODE_REFRESH). The third one is a pointer to a GadInfo and the last
  765. four parameters describe the position and the width/height of the area of
  766. gadget.
  767. NOTE: The area of the gadget also contains the spacing around the gadget.
  768.       The (suggested) dimensions of the gadget itself can be found in the
  769.       newgadget structure.
  770.  
  771. This function is called in several cases. It is not only called when the
  772. gadget should be created, but also when it should be removed. There are
  773. 6 Modes, which are marked in 'Mode' field of the WinInfo structure.
  774. The Modes are:
  775.  
  776. GG_MODE_NEW:     A new gadget should be created. If you create gadgets you
  777.                  should add them to the GList 'Gadgets' in the WinInfo
  778.                  structure and fill 'Prev' in the same structure with the
  779.                  pointer to the last gadget.
  780.  
  781. GG_MODE_RESIZE:  The gadget should be resized. You must not use
  782.                  GT_SetGadgetAttrs() to change the state of gadtools gadgets,
  783.                  since during the GG_MODE_RESIZE call the gadgets are not
  784.                  bound to any window and GG_SetGadgetAttrs() would not work
  785.                  at this point, but you might use GG_SetLowlevelAttrs().
  786.  
  787. GG_MODE_REFRESH: Redraw the gadget. You need not redraw system-gadgets, since
  788.                  RefreshGList() is called internally.
  789.  
  790. GG_MODE_FREE:    Free the gadget and delete all stored contents
  791.  
  792. GG_MODE_STOP:    Delete the gadget, but keep the contents, that were stored
  793.                  by GG_MODE_BACKUP.
  794.  
  795. GG_MODE_BACKUP:  Store the complete information of the gadget e.g. if the
  796.                  gadget is disabled and the selection-state. You may store
  797.                  that information in the Code field of the delivered GadInfo
  798.                  structure and the information if it is disabled can be
  799.                  stored using the flag GG_FLAG_DISABLED in 'dim.Flags' of
  800.                  this structure. You must not change any other bits in this
  801.                  field.
  802.  
  803. GG_MODE_RESTORE: Restore the information that was stored with GG_MODE_BACKUP.
  804.  
  805.  
  806. If you just want to draw some lines, you should ignore the latter three
  807. cases that are only important for the handling of gadgets or 'SubGui's. In
  808. these cases the contents of the NewGadget structure are not valid, however
  809. you will get a pointer to such a structure to avoid enforcer-hits.
  810. You can also use the field Render in the WinInfo structure to determine if
  811. you have draw your lines. It is set to 1 if drawing is needed and to 0 if
  812. not.
  813.  
  814. You must return 0 if everything was OK and any value !=0 if an error
  815. occurred.
  816.  
  817. If you want to draw some lines and render another GUI in this area you can
  818. use "SubGuis". Therefore you must describe a complete GUI just like before
  819. and render this GUI with GG_SubGui() to the window. This function takes the
  820. same parameters as RenderGui() plus four additional parameters which
  821. describe the position and the dimensions of the GUI. You must call this
  822. every time your customfunction is called. This function returns 0 on success
  823. and a value !=0 if an error occurred. In this case your function must
  824. also return a value !=0 to tell that there was an error.
  825. There is another thing that is possible using 'SubGuis', that are
  826. multiplexed user-interfaces. You might have several groups of gadgets that
  827. are rendered to the same place in the window and e.g. a global variable
  828. decides which of these groups is displayed in the window. Note that you must
  829. remove the complete GUI from the window first, if you want to switch the
  830. groups, but you cannot use FreeGui(), since this would lose the complete
  831. information that is stored in the GUI. StopGui() exists for this case. It
  832. stores this information and removes the GUI after this. The next time you
  833. call RenderGUI this information is restored. StopGUI() can also be used
  834. if you want to keep informations although you want to close the window,
  835. because you might reopen it later. See also the example for multiplexed
  836. interfaces.
  837.  
  838.  
  839.  
  840. 8. The functions in the runtime-library "gengui_lnk.o"
  841. ======================================================
  842.  
  843.  
  844. GG_BeginResizeGui:
  845.  
  846.    void GG_BeginResizeGui(struct WinInfo *winfo)
  847.  
  848.    You can use this function to speed up the process of resizing the GUI.
  849.    Therefore you have to use IDCMP_SIZEVERIFY, which signals your program,
  850.    that the user wants to resize the GUI. If you call GG_BeginResizeGui,
  851.    when this happens, all gadgets are detached from the window and intuition
  852.    does no refresh on these gadgets, which would be useless anyways, since
  853.    the GUI is refreshed after it has been resized. But note, you really
  854.    should know, that if you don't handle this message immediately, you may
  855.    get a deadlock of your system. Therefore don't use IDCMP_SIZEVERIFY if
  856.    you are not sure about the side-effects of switching on this
  857.    message-type. It's probably better to have a slightly slower program,
  858.    than a buggy program.
  859.  
  860.  
  861.  
  862. GG_ClearWindow:
  863.  
  864.    void GG_ClearWindow(struct Window *)
  865.  
  866.    Removes all contents from the window, erases the inner of the window
  867.    with the EraseRect() and refreshes the windowborders.
  868.  
  869.  
  870.  
  871. GG_FreeGui:
  872.  
  873.    void  GG_FreeGui(struct WinInfo *winfo)
  874.  
  875.    GG_FreeGui removes the gadgets from the window. It is save to call this
  876.    functions for already freed GUIs.
  877.  
  878.  
  879.  
  880. GG_GetIMsg:
  881.  
  882.    struct IntuiMessage *GG_GetIMsg(struct MsgPort *)
  883.  
  884.    You must call this function instead of GT_GetIMsg() or GetMsg().
  885.    It returns a pointer to an IntuiMessage, if there is a message of
  886.    interest for the program, otherwise it returns NULL. This is for example
  887.    the case if you have a hook-function seleced for a gadget which returns a
  888.    value !=0 to indicate that the message may be ignored.
  889.  
  890.  
  891.  
  892. GG_GfxPrint:
  893.  
  894.    void GG_GfxPrint(struct RastPort *rast,char *text,int left,int top);
  895.  
  896.    This function is used to format and print a text to a RastPort.
  897.    The following format-specifiers are supported:
  898.  
  899.                   \n  : Newline: the next character is printed at the start
  900.                                  of the next line.
  901.                   %%  : '%'
  902.  
  903.                   %Cx : Set foreground color to x
  904.                         (e.g. %C1 : set color to 1)
  905.                   %cx : Set background color to x
  906.  
  907.                   %B  : Bold on
  908.                   %b  : Bold off
  909.                   %I  : Italics on
  910.                   %i  : Italics off
  911.                   %N  : Normal style (Bold,Italics,Underlined off)
  912.                   %U  : Underlined on
  913.                   %u  : Underlined off
  914.  
  915.    Parameters:
  916.             rast     : Pointer to your RastPort
  917.             text     : A pointer to your textstring
  918.             left,top : Left, top corner of the textblock
  919.  
  920.  
  921.  
  922. GG_GfxPrintSize:
  923.  
  924.    void GG_GfxPrintSize(struct RastPort *rast,char *text,struct TextSize *size);
  925.  
  926.    This function is used to calculate the width and height a text
  927.    would occupy when printed with GG_GfxPrint().
  928.  
  929.  
  930.    Parameters:
  931.             rast     : Pointer to your RastPort
  932.             text     : A pointer to your textstring
  933.  
  934.             size     : A pointer to the struct, in which the result will
  935.                        be stored.
  936.  
  937.  
  938.  
  939. GG_MinSize:
  940.  
  941.    void GG_MinSize(struct Window *win, struct WinInfo *gui,
  942.                    struct GG_ObjectSize *size);
  943.  
  944.    GG_MinSize calculates the minimal size for the window win, such that
  945.    the gui will fit within this window. The result is written to 'size',
  946.    which must point to some valid memory-position. This size does not cover
  947.    any bordersizes of the window, these must be added to the calculated
  948.    sizes.
  949.  
  950.  
  951.  
  952. GG_MinSizeFont:
  953.  
  954.    void GG_MinSizeFont(struct TextFont *font, struct WinInfo *gui,
  955.                        struct GG_ObjectSize *size);
  956.  
  957.    GG_MinSizeFont calculates the minimal size for the font 'font', such that
  958.    the gui will fit within window of this (inner) size. The result is
  959.    written to 'size', which must point to some valid memory-position.
  960.    This size does not cover any bordersizes of the window. Therefore
  961.    it would be suitable for opening a window with WA_InnerWidth and
  962.    WA_InnerHeight.
  963.  
  964.  
  965.  
  966. GG_RefreshGui:
  967.  
  968.    int GG_RefreshGui(struct WinInfo *winfo)
  969.  
  970.    This function is used to refresh the gadgets within the window.
  971.    It is only important if you are using SimpleRefresh, since only then it
  972.    is your job to refresh the window. If you are using SmartRefresh windows
  973.    then it should not be required since the system does that job for you.
  974.    It returns 0 if everything was OK.
  975.  
  976.  
  977.  
  978. GG_RenderGui:
  979.  
  980.    int GG_RenderGui(struct Window *win, struct WinInfo *winfo)
  981.  
  982.    GG_RenderGui draws the gadgets to the window. You must supply the pointer
  983.    to the window and the pointer to the WinInfo structure of your GUI.
  984.    This one can be obtained by using the & operator on the name that was
  985.    selected using "PROJECTNAME" in the descriptionfile.
  986.    It returns 0 if everything was OK.
  987.  
  988.  
  989.  
  990. GG_ResizeGui:
  991.  
  992.    int GG_ResizeGui(struct WinInfo *winfo)
  993.  
  994.    This function is used to adapt the GUI to the new size when a window
  995.    has been resized. You must call this function every time you receive
  996.    a IDCMP_NEWSIZE message.
  997.    It returns 0 if everything was OK.
  998.    You can speed up the resizing-process by using GG_BeginResizeGui.
  999.  
  1000.  
  1001.  
  1002. GG_SetGadgetAttrs / GG_SetGadgetAttrsA:
  1003.  
  1004.    BOOL GG_SetGadgetAttrsA(struct Gadget *, struct Window *,
  1005.                            struct Requester *, struct TagItem *)
  1006.  
  1007.    BOOL GG_SetGadgetAttrs(struct Gadget *, struct Window *,
  1008.                            struct Requester *, Tag, ...)
  1009.  
  1010.  
  1011.    This is a replacemet for the function GT_SetGadgetAttrs of
  1012.    gadtools.library. You must call this function instead of that of gadtools,
  1013.    since Gengui needs to keep track of the information stored in the gadgets.
  1014.    NOTE: Whereas the gadtools function returns VOID this one returns if it
  1015.          was successful to modify the attributes. If there is not enough
  1016.          memory it returns 0 to indicate that there was an error and the
  1017.          attributes are not changed.
  1018.  
  1019.  
  1020. GG_SetLowlevelAttrs / GG_SetLowlevelAttrsA:
  1021.  
  1022.    BOOL GG_SetLowlevelAttrsA(struct GadInfo *, struct TagItem *)
  1023.  
  1024.    BOOL GG_SetLowlevelAttrs(struct GadInfo *, Tag, ...)
  1025.  
  1026.    Whereas the GG_SetAttrs function cannot be used, as long as the
  1027.    GUI is not rendered to a window, and cannot be used for changing tags,
  1028.    that cannot be changed as long as Gadgets are rendered to a window,
  1029.    e.g. the depth of a palette-gadget, these functions can do this magic
  1030.    thing. If the GUI is already rendered to a window, you must call
  1031.    GG_ResizeGui after this function, to make these changes take effect.
  1032.    GG_ResizeGui removes and recreates all gadgets and this allows to
  1033.    change really all tags.
  1034.  
  1035.  
  1036.  
  1037. GG_SmartRenderGui:
  1038.  
  1039.    int  GG_SmartRenderGui(struct Window *win, struct WinInfo *winfo,
  1040.                           struct TextFont **font)
  1041.  
  1042.    GG_SmartRenderGui determines the minimum size of the GUI and adjusts the
  1043.    window according to this information. Therefore it may resize and move
  1044.    the window and if this is not sufficient, it will switch to another font.
  1045.    Therefore you must call it with a pointer to a pointer to a font.
  1046.    If this pointer is a nullpointer, then it will open the topaz 80 font,
  1047.    in the other case it will use the delivered font as a fall-back font.
  1048.    It is up to you to close this font, when your program exits. If the GUI
  1049.    would not fit within the window, although it already uses the fall-back-
  1050.    font, it ignores that and the display might look messed up, but that's
  1051.    probably better, than not being able to display anything at all,
  1052.    since the user then really has no chance to use the program.
  1053.  
  1054.    GG_SmartRenderGui draws the gadgets to the window. You must supply the
  1055.    pointer to the window and the pointer to the WinInfo structure of your
  1056.    GUI. This one can be obtained by using the & operator on the name that
  1057.    was selected using "PROJECTNAME" in the descriptionfile.
  1058.    It returns 0 if everything was OK.
  1059.  
  1060.  
  1061.    Input:
  1062.             win:   Pointer to an open Window
  1063.             winfo: Pointer to your GUI, You can obtain this pointer
  1064.                    by using the & operator on the name, you have given
  1065.                    for PROJECTNAME in the descriptionfile
  1066.             font:  Pointer to an pointer to an fall-back-font or to a
  1067.                    NULL-pointer.
  1068.  
  1069.  
  1070.    Result: 0 if everything was OK
  1071.  
  1072.  
  1073.    Example:
  1074.  
  1075.       struct TextFont *font=NULL;
  1076.  
  1077.  
  1078.       ...
  1079.  
  1080.       /* Open your window */
  1081.  
  1082.  
  1083.  
  1084.       if(GG_SmartRenderGui(win,&Gui,&font)) {
  1085.  
  1086.          /* failed */
  1087.  
  1088.          CloseWindow(win);
  1089.          if(font) CloseFont(font);
  1090.  
  1091.          /* additional error-handling */
  1092.       }
  1093.  
  1094.  
  1095.  
  1096.       ... /* Your code goes here */
  1097.  
  1098.       CloseWindow(win)
  1099.       if(font) CloseFont(font); /* you must not close it, as long as
  1100.                                    the window stays open, since it will be
  1101.                                    uses as long as this window exists */
  1102.  
  1103.  
  1104.  
  1105.    Notes:
  1106.       - If you call it with your own fall-back font, that was obtained by
  1107.         OpenDiskFont, you must call CloseDiskFont instead of CloseFont.
  1108.  
  1109.       - The fall-back font should definitely be smaller than the default-font,
  1110.  
  1111.  
  1112.  
  1113. GG_StopGui:
  1114.  
  1115.    void GG_StopGui(struct WinInfo *winfo)
  1116.  
  1117.    GG_StopGui() stores the information of the gadgets and removes them after
  1118.    this from the window. GG_RenderGui() will recognize if the information was
  1119.    stored and will restore them if this was the case.
  1120.  
  1121.  
  1122.  
  1123. GG_SubGui:
  1124.  
  1125.    int GG_SubGui(struct WinInfo *parent, struct WinInfo *winfo,
  1126.               int left,int top,int width, int height)
  1127.  
  1128.    GG_SubGui allows to draw GUIs within another GUI. You must not use this
  1129.    function for other purposes. It is not possible to render a GUI only
  1130.    with this function. You must use GG_RenderGui() for this, since it
  1131.    allocates some additional resources wich are also required by GG_SubGui
  1132.    and must be already allocated when GG_SubGui is called.
  1133.  
  1134.  
  1135.  
  1136.  
  1137. Useful Macros:
  1138. --------------
  1139.  
  1140. GetString:
  1141.  
  1142.    UBYTE * GetString(struct Gadget *)
  1143.  
  1144.    This macro returns a pointer to the contents of a string-gadget if passed
  1145.    a pointer to the string-gadget.
  1146.  
  1147.  
  1148. GetNumber:
  1149.  
  1150.    LONG GetNumber(struct Gadget *)
  1151.  
  1152.    This macro returns the contents of a integer-gadget if passed
  1153.    a pointer to the integer-gadget.
  1154.  
  1155.  
  1156. GetInfo:
  1157.  
  1158.    struct GadInfo * GetInfo(struct Gadget *)
  1159.  
  1160.    This macro returns a pointer to the correlated GadInfo structure of a
  1161.    given gadget.
  1162.  
  1163.  
  1164. GetUserData:
  1165.  
  1166.    ULONG GetUserData(struct Gadget *)
  1167.  
  1168.    This macro returns a the userdata of the given gadget.
  1169.  
  1170.    NOTE: You cannot use the udserdata-field of gadtools gadgets, since
  1171.          this field is required by the gengui link-library for internal use.
  1172.  
  1173.  
  1174. GetGadget:
  1175.  
  1176.    struct Gadget * GetGadget(struct IntuiMessage *)
  1177.  
  1178.    This macro calculates the address of the gadget in an intuimessage
  1179.    of the type IDCMP_GADGETUP or IDCMP_GADGETDOWN
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185. 9. Compiling
  1186. ============
  1187.  
  1188. You need to compile gengui_lnk.c in the Gui_lib directory and link this to
  1189. your program. Of course you need not recompile it every time. Just compile
  1190. it with your favourite C-compiler and then link gengui_lnk.o to your program.
  1191. If you are using SAS-C, then you can use the already compiled module in this
  1192. directory.
  1193.  
  1194.  
  1195.  
  1196. 10. What's new
  1197. =============
  1198.  
  1199. GenGui has some additional capabilities for designing GUI's. There are:
  1200.  
  1201. - frames
  1202. - bars
  1203. - graphical buttons
  1204. - formatted texts
  1205. - backgound patterns
  1206.  
  1207. Furthermore GenGui is now able to determine the minimum size of the window
  1208. the GUI should be rendered to. Therefore there is a new set of commands
  1209. for the description language, to determine the minimum size for boxes or
  1210. gadgets with relative size. The user is supported by a quite complex
  1211. default-mechanism, so that he need not give any information in most cases.
  1212.  
  1213.  
  1214. Then I have cleaned up the names of the interface for gengui. But don't
  1215. panic, if you define GG_OLDSTYLE you will get the old names for
  1216. compatibility reasons.
  1217.  
  1218. NOTE: It is not possible just to link with the new link-library, you have
  1219.       also to recompile the GUI-description with the new gengui, but that
  1220.       shouldn't be a problem.
  1221.  
  1222. NOTE2: You should not use Gui_GetIMsg any more, which internally replies
  1223.       the Intuimessage, since this could mess up multi-selections of menus.
  1224.       Instead you should use GG_GetIMsg() and GG_ReplyMsg().
  1225.  
  1226.  
  1227.  
  1228. 11. Credits
  1229. ===========
  1230.  
  1231. Thanks to all who have sent me bug-reports and / or suggestions for
  1232. improvements of this tool.
  1233.  
  1234. @EndNode
  1235.  
  1236.